package com.group8.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

import com.group8.gm.GameController;

public class MainMenu extends Menu{
	private JButton play;
	private JButton settings;
	private JButton credits;
	private JButton help;
	private JButton highS;
	private JButton back;
	private GameController gc;
	private MainMenu m;
	private JLabel score;
	
	public MainMenu(){
		play = new JButton();
		Image img1 = new ImageIcon("assets/main_menu/playGame.png").getImage();
		play.setIcon(new ImageIcon(img1));
		
		settings = new JButton();
		Image img2 = new ImageIcon("assets/main_menu/settings.png").getImage();
		settings.setIcon(new ImageIcon(img2));
		
		credits = new JButton();
		Image img3 = new ImageIcon("assets/main_menu/credits.png").getImage();
		credits.setIcon(new ImageIcon(img3));
		
		help = new JButton();
		Image img4 = new ImageIcon("assets/main_menu/help.png").getImage();
		help.setIcon(new ImageIcon(img4));
		
		highS = new JButton();
		Image img5 = new ImageIcon("assets/main_menu/highscores.png").getImage();
		highS.setIcon(new ImageIcon(img5));
		
		back = new JButton();
		Image img6 = new ImageIcon("assets/main_menu/back.png").getImage();
		back.setIcon(new ImageIcon(img6));
		setLayout(null);
		
		ButtonListener listener = new ButtonListener();
		play.setRolloverEnabled(false);
		settings.setRolloverEnabled(false);
		highS.setRolloverEnabled(false);
		credits.setRolloverEnabled(false);
		help.setRolloverEnabled(false);
		play.setBounds(200,500,158,40);
		settings.setBounds(450,400,137,40);
		help.setBounds(270,330,92,40);
		highS.setBounds(370,230,176,40);
		credits.setBounds(220,140,125,40);
		add(play);
		add(settings);
		add(help);
		add(highS);
		add(credits);
		score = new JLabel();
		play.addActionListener(listener);
		settings.addActionListener(listener);
		help.addActionListener(listener);
		highS.addActionListener(listener);
		credits.addActionListener(listener);
		m = this;
		setPreferredSize(new Dimension(800,660));
	}
	
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		Image img = new ImageIcon("assets/background.jpg").getImage();
		g.drawImage(img, 0, 0, null);
	}
	
	public void startGame() {
		
	}
	public void addScore(int s){
		score.setForeground(Color.RED);
		score.setFont(new Font("nfont", Font.PLAIN, 30));
		score.setBounds(200, 50, 500, 50);
		score.setText("Game is over. Your score is : "+ s);
		add(score);
	}
	public void endGame() {
		
	}
	public void setGC(GameController g){
		super.setGC(g);
	}
	//button listener
	private class ButtonListener extends MenuActionListener{
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if(e.getSource() == play){
				gc = new GameController();
				setGC(gc);
				
				System.out.println("Initializing/retrieving the game panel");
				
				switchPanels(gc.getGamePanel());
				gc.setMenu(m);
				
				gc.getGamePanel().addKeyListener(gc.getIM());
				gc.getGamePanel().setFocusable(true);
				gc.getGamePanel().requestFocusInWindow();
				

			} else if(e.getSource() == highS) {
				System.out.println("High Scores Clicked");
				HighScorePanel p = new HighScorePanel();
				switchPanels(p);
			}
			else if(e.getSource() == settings){
				System.out.println("Settings Clicked");
				SettingsPanel sp = new SettingsPanel();
				switchPanels(sp);
			}
			else if(e.getSource() == help){
				System.out.println("Help clicked");
				HelpPanel hp = new HelpPanel();
				switchPanels(hp);
			}
			else if(e.getSource() == credits){
				System.out.println("Credits clicked");
				CreditsPanel cp = new CreditsPanel();
				switchPanels(cp);
			}
				
			
		}
		
	}
	
}